package com.pingtai.manage.service;


import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.criterion.Order;

import com.pingtai.common.entity.IndexPointOut;
import com.pingtai.dao.AbstractManager;
import com.pingtai.indent.dao.IndentTypeDao;
import com.pingtai.indent.entity.UserBaseIndentType;
import com.pingtai.indent.service.WeiboIndentService;
import com.pingtai.manage.dao.NoticeDao;
import com.pingtai.user.entity.User;
import com.pingtai.user.service.UserManagerService;
import com.pingtai.util.PaginationSupport;

public class ProduceManageService {
	private UserManagerService userManagerService;
	private WeiboIndentService weiboIndentService;
	private AbstractManager abstractManager;
	public UserManagerService getUserManagerService() {
		return userManagerService;
	}
	public void setUserManagerService(UserManagerService userManagerService) {
		this.userManagerService = userManagerService;
	}
	public WeiboIndentService getWeiboIndentService() {
		return weiboIndentService;
	}
	public void setWeiboIndentService(WeiboIndentService weiboIndentService) {
		this.weiboIndentService = weiboIndentService;
	}
	public AbstractManager getAbstractManager() {
		return abstractManager;
	}
	public void setAbstractManager(AbstractManager abstractManager) {
		this.abstractManager = abstractManager;
	}
	
	private IndentTypeDao indentTypeDao;
	
	
	
	public IndentTypeDao getIndentTypeDao() {
		return indentTypeDao;
	}
	public void setIndentTypeDao(IndentTypeDao indentTypeDao) {
		this.indentTypeDao = indentTypeDao;
	}
	
	public PaginationSupport getBaseIndentTypeForPage(int pageName){
		Session session = indentTypeDao.getSession();
		Criteria criteria = session.createCriteria(UserBaseIndentType.class);

		User user = userManagerService.findCurrectUser();
		
		criteria.addOrder(
				Order.asc("sort2"));
		return abstractManager.findPageByCriteria(criteria, pageName);
	}
	
	public void updateBaseProduce(UserBaseIndentType base){
		indentTypeDao.update(base);
	}
	
	public void updatePointOutForIndex(IndexPointOut pointOut){
		indentTypeDao.update(pointOut);
	}
	
	public IndexPointOut getIndexPointOut(){
		Query query = indentTypeDao.getSession().createQuery("from IndexPointOut where id=1");
		List list = query.list();
		if(list!=null&&list.size()>0){
			return (IndexPointOut) list.get(0);
		}
		
		return null;
	}
	public IndexPointOut getIndexPointOut(Integer id){
		Query query = indentTypeDao.getSession().createQuery("from IndexPointOut where id=:id");
		query.setParameter("id", id);
		List list = query.list();
		if(list!=null&&list.size()>0){
			return (IndexPointOut) list.get(0);
		}
		
		return null;
	}
}
